package com.hailin.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hailin.lease.model.entity.SystemPost;
import com.hailin.lease.model.entity.SystemUser;
import com.hailin.lease.web.admin.mapper.SystemUserMapper;
import com.hailin.lease.web.admin.service.SystemPostService;
import com.hailin.lease.web.admin.service.SystemUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hailin.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.hailin.lease.web.admin.vo.system.user.SystemUserQueryVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {

    @Autowired
    private SystemUserMapper systemUserMapper;

    @Autowired
    private SystemPostService systemPostService;
    /**
     * 员工分页查询
     * @param page
     * @param queryVo
     * @return
     */
    public IPage<SystemUserItemVo> pageQuery(IPage<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        return systemUserMapper.pageQuery(page, queryVo);
    }

    /**
     * 根据id查询员工信息
     * @param id
     * @return
     */
    public SystemUserItemVo getUserItemById(Long id) {
        SystemUser systemUser = super.getById(id);
        Long postId = systemUser.getPostId();
        SystemPost systemPost = systemPostService.getById(postId);
        SystemUserItemVo systemUserItemVo = new SystemUserItemVo();
        if (systemUser != null) {
            BeanUtils.copyProperties(systemUser, systemUserItemVo);
            systemUserItemVo.setPostName(systemPost.getName());
        }
        return systemUserItemVo;
    }

    /**
     * 登录根据用户名查询
     * @param username
     * @return
     */
    public SystemUser getByUsername(String username) {
        return systemUserMapper.getByUsername(username);
    }
}




